package com.example.chao.myphotosearch.adapters;

import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.example.chao.myphotosearch.adapters.holders.BaseViewHolder;
import com.example.chao.myphotosearch.adapters.holders.HeadHolder;
import com.example.chao.myphotosearch.adapters.holders.MainViewHolder;
import com.example.chao.myphotosearch.dao.Recommend;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by chao on 2016/3/19.
 */
public class MainAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private static final int HEAD = 0;
    private static final int CONTENT = 1;
    private List<Recommend> recommendLists;
    @Inject
    public MainAdapter(){
        this.recommendLists = new ArrayList<>();
    }
//    private List<BaseViewHolder> holders;
    public void setRecommendLists(List<Recommend> recommendLists){
        if(recommendLists!=null) {
            this.recommendLists = recommendLists;
//            holders.clear();
            notifyDataSetChanged();
        }
    }
    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return HEAD;
        } else{
            return CONTENT;
        }
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == HEAD) {
            return new HeadHolder(parent);
        } else {
            return  new MainViewHolder(parent);
        }
    }

    @Override
    public void onBindViewHolder( BaseViewHolder holder, int position) {
                holder.setData(recommendLists.get(position));
    }

    @Override
    public int getItemCount() {
        return recommendLists.size();
    }
}
